package person.csx.meeting.service.impl;


import org.springframework.beans.factory.annotation.Autowired;
import person.csx.meeting.model.Employee;
import person.csx.meeting.service.EmployeeService;
import person.csx.meeting.mapper.EmployeeMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public List<Employee> list() {
        return employeeMapper.selectList(null);
    }

    public Employee doLogin(String username, String password) {
        Employee employee = employeeMapper.loadEmpByUsername(username);
        //首先排除用户名不存在或者密码输入错误
        if (employee == null || !employee.getPassword().equals(password)) {
            return null;
        }
        return employee;
    }

    @Override
    public Integer doRegister(Employee employee) {
        Employee emp = employeeMapper.loadEmpByUsername(employee.getUsername());
        if (emp != null) {
            return -1;
        }

        employee.setRole("1");

        employee.setStatus("0");
        return employeeMapper.doRegister(employee);
    }

    @Override
    public List<Employee> getAllEmpStatus(Integer status) {
        return employeeMapper.getAllEmpStatus(status);
    }

    @Override
    public List<Employee> getAllEmp(Employee employee) {
        return employeeMapper.getAllEmp(employee);
    }
}










